package com.opengroupe.dto;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

public class SingleQuestionReponse implements Serializable{

	
	/**
	 * 
	 */
	private static final long serialVersionUID = -241242735332626078L;
	private QuestionDto question;
	private List<Integer> _idsReponsesCandidat;
	
	public SingleQuestionReponse() {
	}
	
	public SingleQuestionReponse(QuestionDto question, List<Integer> idsReponsesCandidat) {
		this.question = question;
		this._idsReponsesCandidat = idsReponsesCandidat;
	}
	

	public QuestionDto getQuestion() {
		return this.question;
	}

	public void setQuestion(QuestionDto question) {
		this.question = question;
	}

	public List<Integer> getIdsReponsesCandidat() {
		return this._idsReponsesCandidat;
	}

	public void setIdsReponsesCandidat(List<Integer> idsReponsesCandidat) {
		this._idsReponsesCandidat = idsReponsesCandidat;
	}

	public boolean questionCorrecte() {
		List<ReponseDto> reponses = question.getReponses();
		
		boolean correcte = true;
		ReponseDto reponse = null;
		
		for(int k=0;k<reponses.size();k++){
			reponse = reponses.get(k);
			if (reponse.getCorrect() && !_idsReponsesCandidat.contains(reponse.getIdReponse())
					|| !reponse.getCorrect() && _idsReponsesCandidat.contains(reponse.getIdReponse())) {
				correcte = false;
				break;
			}
		}
		
		return correcte;
	}
	
	public List<SingleReponse> getReponses()
	{
		ArrayList<SingleReponse> liste = new ArrayList<SingleReponse>();
		ReponseDto reponse = null;
		
		for (int i=0; i< this.question.getReponses().size(); i++)
		{
			reponse = this.question.getReponses().get(i);
		
			liste.add(new SingleReponse(
					reponse, 
					_idsReponsesCandidat.contains(reponse.getIdReponse())
					));
		}
		
		return liste;
	}
	
	
}



